package com.xdwanj.dao.impl;

import com.xdwanj.dao.BaseDao;
import com.xdwanj.dao.RoleDao;
import com.xdwanj.pojo.Role;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class RoleDaoImpl implements RoleDao {
    BaseDao baseDao = new BaseDao();

    JdbcTemplate jdbcTemplate = baseDao.getJdbcTemplate();

    @Override
    public List<Role> findRoleAllList(int id) throws Exception {
        StringBuffer sql = new StringBuffer("select * from role");
        if (id != 0) {
            sql.append(" where id = ?");
            return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Role>(Role.class), id);
        }
        return jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper<Role>(Role.class));
    }
}
